import { createSlice } from '@reduxjs/toolkit'

export const tokenSlice = createSlice({
  name: 'token',
  initialState: localStorage.getItem('token') || '',
  reducers: {
    set: (_, action) => {
      localStorage.setItem('token', action.payload || '')
      return action.payload || ''
    }
  }
})

export const { set } = tokenSlice.actions

export default tokenSlice.reducer
